#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright @ 2014 OPS, Qunar Inc. (qunar.com)
#
# Author: tingfang.bao <tingfang.bao@qunar.com>
# DateTime: 15-3-9 下午12:30
from flask import Flask

app = Flask(__name__)


@app.route('/', methods=['GET'])
def index():
    print 'view func...'
    return 'index'


@app.before_request
def before_request():
    print 'before request...'


@app.after_request
def after_request(exception=None):
    print 'after request...'


@app.teardown_request
def teardown_request(exception=None):
    print 'teardown request...'


ctx = app.test_request_context("/")
ctx.push()

# 调用before_request方法
app.preprocess_request()

# 这里可以触发after_request
print 'x' * 144
app.process_response(app.response_class())
print 'y' * 144

ctx.pop()